package com.wondream.myframework.app.common.log;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.wondream.myframework.app.common.util.JacksonUtil;
import com.wondream.myframework.app.common.util.MD5Util;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

@Data
public class Log {

    private static final Logger log = LoggerFactory.getLogger(Log.class);

//    static ValueFilter valueFilter = pro

    protected static ObjectMapper mapper = new ObjectMapper();

    private String operation;

    private Map<String, Object> params = new HashMap<>();

    private String message = "";

    private boolean catReport = false;

    private static final String LOG_FORMAT = "%s|%s|%s|%s";

    private static final String TRACEID = "traceId";

    public Log(String operation) {
        this.operation = operation;
    }

    public static Log op(String op){
        return new Log(op);
    }

    public Log kv(String key, final Object value){
        String valueStr = JacksonUtil.toJson(value);
        this.params.put(key, valueStr);
        return this;
    }

    public Log notMask(String key, final Object value){
        String valueStr = JacksonUtil.toJson(value);
        this.params.put(key, valueStr);
        return this;
    }

    public Log msg(String message, Object... args){
        this.message = String.format(message, args);
        return this;
    }

    public Log catReport(boolean flag){
        this.catReport = flag;
        return this;
    }

    public String toString(){
        String result = String.format(LOG_FORMAT, this.message, this.params.toString(),this.operation,this.catReport);
        return result;
    }

}
